Skip to content

Conversation

@kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Jan 9, 2025

This PR does not change the functionality of the CLI (yet)

It does however articulate a schema for what cdk.json should look like in the future. I'm aware that we honor a slightly different set of rules in cdk.json that is not documented anywhere, and we will have to honor those rules ad-hoc. However, this will hopefully move us towards a strongly-typed future where cdk.json contents mirror CLI argument options.

  • global options are specified at the base level of cdk.json
  • command specific options will be prefixed by their command name. NOTE: some options are honored at the base level today. I will have to, in a separate PR, find each of these instances and take care of them but ensuring we still map them to the correct place in CliArguments.
{
  "app": "npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts",
  "output": "cdk.out",
  "build": "npx projen bundle",
  "watch": {
      "exclude": [
        "README.md",
        "cdk*.json",
        "**/*.d.ts",
        "**/*.js",
        "tsconfig.json",
        "package*.json",
        "yarn.lock",
        "node_modules"
    ]
}

This will turn into the following CliArgument object:

{
  globalOptions: {
    app:  'npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts',
    output: 'cdk.out',
    build: 'npx projen bundle',
    watch: {
      exclude: [
          "README.md",
          "cdk*.json",
          "**/*.d.ts",
          "**/*.js",
          "tsconfig.json",
          "package*.json",
          "yarn.lock",
          "node_modules",
      ],
   },
};

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@kaizencc kaizencc requested a review from a team as a code owner January 9, 2025 01:04
@aws-cdk-automation aws-cdk-automation requested a review from a team January 9, 2025 01:04
@github-actions github-actions bot added the p2 label Jan 9, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 9, 2025
@kaizencc kaizencc changed the title chore(cli): generate schema for cdk.json configuration chore(cli): generate conversion from cdk.json to cli arguments Jan 9, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Jan 9, 2025
@codecov
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.52%. Comparing base (d6013a7) to head (d11171a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32803   +/-   ##
=======================================
  Coverage   81.52%   81.52%           
=======================================
  Files         222      222           
  Lines       13717    13717           
  Branches     2417     2417           
=======================================
  Hits        11183    11183           
  Misses       2254     2254           
  Partials      280      280           
Flag Coverage Δ
suite.unit 81.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.98% <ø> (ø)
packages/aws-cdk-lib/core 82.09% <ø> (ø)

* The CLI command name
*/
readonly _: Command;
readonly _?: Command;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed because cdk.json doesn't have a specific command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just make it two different interface then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's necessary. CliArguments does/should not do any enforcing. Enforcement comes from sending our CLI input through yargs. Therefore, I think it makes sense that every option on CliArguments is optional. It's just a schema for config options.

Arguably, CliArguments is now a misnomer because it governs both CLI options and cdk.json options. But the goal is to make sure those two are one and the same anyway.

Would it alleviate your concerns if I renamed CliArguments into Arguments?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not CLI anymore, there's no reason to call it _. We only do that because of yargs.

I think we are turning it into structured user input, so maybe something along the lines of UserInput?

Copy link
Contributor Author

@kaizencc kaizencc Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rename CliArguments to UserInput, and rename _ to command in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaizencc kaizencc added pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested and removed pr/needs-cli-test-run This PR needs CLI tests run against it. labels Jan 9, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 9, 2025 04:11

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 9, 2025
const cliArguments: CliArguments = {
globalOptions,
list: listOptions,
synthesize: synthesizeOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should synth be the main name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that can be done but that would have to be a change to config.ts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the impact here? When are we committing to a specific action name in cdk.json? I think we need to make that call before we are committing to it. WDYT about synth vs synthesize though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will create a separate PR that changes the default name of synthesize to synth. I believe we've standardized on that, and up until now yargs allows them to work interchangably. Existing configurations should not change, and then we will allow synth as the keyword in cdk.json to provide default configs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor feedback.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 9, 2025
@mrgrain mrgrain added the pr/do-not-merge This PR should not be merged at this time. label Jan 9, 2025
@kaizencc kaizencc removed the pr/do-not-merge This PR should not be merged at this time. label Jan 9, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: d5c3c56
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Jan 9, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@kaizencc kaizencc merged commit b670ba8 into main Jan 9, 2025
10 of 11 checks passed
@kaizencc kaizencc deleted the conroy/generateconfig branch January 9, 2025 23:14
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants